#include "taskQueue.h"

int initQueue(taskQueue_t *pQueue){
    bzero(pQueue,sizeof(taskQueue_t));
    return 0;
}

int enQueue(taskQueue_t *pQueue,int netFd){
    node_t *pNew = (node_t *)calloc(1,sizeof(node_t));
    pNew->netFd = netFd;
    if(pQueue->queueSize == 0){
        pQueue->pFront = pNew;
        pQueue->pRear = pNew;
    }
    else{
        pQueue->pRear->pnext = pNew;
        pQueue->pRear = pNew;
    }
    ++pQueue->queueSize;
    return 0;
}

int deQueue(taskQueue_t *pQueue){
    node_t *pCur = pQueue->pFront;
    pQueue->pFront = pCur->pnext;
    if(pQueue->queueSize == 1){
        pQueue->pRear = NULL;
    }
    free(pCur);
    --pQueue->queueSize;
    return 0;
}

int visitQueue(taskQueue_t *pQueue){
    node_t *pCur = pQueue->pFront;
    while(pCur){
        printf("%3d",pCur->netFd);
        pCur = pCur->pnext;
    }
    printf("\n");
    return 0;
}
